<?php
require ('../include/init.inc.php');
$serial_number =  '';
extract ( $_POST, EXTR_IF_EXISTS );

if (Common::isPost ()) {

	$allFields =  MachineVistor::getDbField();
	foreach ($allFields  as $v){
		$key = $v["COLUMN_NAME"];
		$input_data[$key] = trim($_POST[$key]);
	}
	
	$input_data["create_user_id"] = UserSession::getUserId();
	$input_data["create_time"] = date("Y-m-d H:i:s");
	unset($input_data["id"]);
	$MachineVistorId = MachineVistor::addMachineVistor ( $input_data );
	
	if ($MachineVistorId) {
		$update_time = array("last_vistor_time"=>$input_data["create_time"]) ;
		Machine::updateMachineInfo($input_data["machine_id"], $update_time);//TODO
		SysLog::addLog ( UserSession::getUserName(), 'ADD', 'MachineVistor' ,$MachineVistorId, json_encode($input_data) );
		Common::exitWithSuccess ('主机拜访记录添加完成','panel/machine_modify.php?method=modify&machine_id='.$input_data["machine_id"]);
	}
}

Template::display('panel/machine_add.tpl' );
